<?php

namespace App\Admin\Controllers;

use App\UserVipOrder;
use App\UserVipReceive;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class UserVipController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '会员购买记录';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new UserVipReceive());
        $grid->model()->orderBy('id', 'desc');
        $grid->filter(function($filter) {
            // 去掉默认的id过滤器
            $filter->disableIdFilter();
            // 设置datetime类型
            $filter->equal('transaction_no', '业务单号');
            $filter->like('user.name', '买家名称');
            $filter->like('user.phone', '买家手机号');
            $filter->between('created_at', '下单时间')->datetime();
            $filter->where(function ($query) {
                switch ($this->input) {
                    case 'yes':
                        $query->where('status', 2);
                        break;
                    case 'no':
                        $query->where('status', '<>', 2);
                        break;
                }
            }, '订单状态')->radio([
                'yes' => '已完成',
                'no' => '未完成',
            ]);

        });

        $grid->column('wx_no', '业务单号丨支付流水号')->display(function($value){
            return "{$this->transaction_no}<br/>{$value}";
        });
        $grid->column('type', '商品')->display(function($value){
            switch ($value){
                case 1: return "注册领取<br/>Plus会员+".$this->num;break;
                case 2: return "签到领取<br/>Plus会员+".$this->num;break;
                case 3: return "订单满5<br/>Plus会员+".$this->num;break;
                case 4: return "Plus会员+".$this->num;break;
                case 5: return "商家赠送Plus会员+".$this->num;break;
                default: return '';
            }
        });
        $grid->column('user.name', '用户名')->display(function($value){
            return $value.'<br/>'.$this->user->phone;
        });
        $grid->column('amount', '实付');
        $grid->column('status', '状态')->using(['待支付','支付中','已支付','支付失败']);
        $grid->column('created_at', '下单时间');
        $grid->disableActions();
        return $grid;
    }

}
